package controller;

import java.io.IOException;
import java.sql.ResultSet;

import studysystem.db.MySQLConnector;
import application.Main;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.stage.Stage;

public class Test2Controller {
	@FXML
	private RadioButton right1;
	@FXML
	private RadioButton right2;
	@FXML
	private RadioButton right3;
	@FXML
	private RadioButton right4;
	@FXML
	private RadioButton right5;
	@FXML
	private RadioButton right6;
	@FXML
	private Button estimatebtn;
	int score=0;
	@FXML
	private Button exitbtn; 
	@FXML
	private Label passed; 
	@FXML
	private Label failed; 
	@FXML
	private Label yourscore; 
	@FXML
	private Label text; 
	
	public void  estimate(ActionEvent event)
	{
		if (right1.isSelected())
		{score++;}
		if (right2.isSelected())
		{score++;}
		if (right3.isSelected())
		{score++;}
		if (right4.isSelected())
		{score++;}
		if (right5.isSelected())
		{score++;}
		if (right6.isSelected())
		{score++;}
		exitbtn.setVisible(true);
		text.setVisible(true);
		yourscore.setVisible(true);
		estimatebtn.setVisible(false);
		yourscore.setText(""+score);
		if (score<4)
		{
			failed.setVisible(true);
		}
		else {
			passed.setVisible(true);
			 MySQLConnector conn;
			try {
				conn = new MySQLConnector();
				 conn.execSQLUpdate("INSERT INTO Available_chapters(chapter_id, user_id) values ('3','"+Main.id+"')");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			 }
        
		}
	public void  exittomain(ActionEvent event)
	{
	 Parent root;
	try {
			
		root = FXMLLoader.load(getClass().getResource("/application/MainScreen.fxml"));
		Scene scene = new Scene(root); 
		//stage= new Stage();
		Stage stage = (Stage) exitbtn.getScene().getWindow();
		stage.setScene(scene);
		stage.show();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
		
	}
	}

